<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>创建职位</span>
      </div>
      <el-form :model="form" :rules="rules" ref="form" label-width="120px" style="width: 500px">
        <el-form-item label="职位名" prop="jobName">
          <el-input v-model="form.jobName"></el-input>
        </el-form-item>
        <el-form-item label="职位描述" prop="jobDesc">
          <el-input v-model="form.jobDesc"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio label="1">关闭</el-radio>
            <el-radio label="2">开启</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="面试官" prop="interviewerId">
          <el-select v-model="form.interviewerId">
            <el-option label="面试官1" value="1"></el-option>
            <el-option label="面试官2" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="提示词前缀" prop="prompt">
          <el-input v-model="form.prompt"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">立即提交</el-button>
          <el-button @click="resetForm">取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>

import http from '@/http.js'; // 导入封装好的axios实例
export default {
  data() {
    return {
      form: {

      },
      rules: {
        jobName: [
          { required: true, message: '职位名不能为空', trigger: 'blur' }
        ],
        jobDesc: [
          { required: true, message: '职位描述不能为空', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '请选择状态', trigger: 'change' }
        ],
        interviewerId: [
          { required: true, message: '请选择面试官', trigger: 'change' }
        ],
        prompt: [
          { required: true, message: '提示词前缀不能为空', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          // 这里可以添加提交表单数据的逻辑，例如发送AJAX请求
          console.log('表单提交成功', this.form);
          http.post('/job/addJob',this.form).then(res=>{
            this.$router.push('/jobList');
          })
        } else {
          console.log('表单验证失败');
          return false;
        }
      });
    },
    resetForm() {
      this.$refs.form.resetFields();
    }
  }
};
</script>

<style scoped>
.box-card {
         margin-bottom: 20px;
       }
</style>